from apscheduler.schedulers.asyncio import AsyncIOScheduler
from modules.admin.models.Orders import Orders

scheduler = AsyncIOScheduler()


class OrderServices:
    @staticmethod
    async def all_status_update(status: str, update_status: str):
        data = Orders.where('status', status).update({"status": update_status})
        return data

    @staticmethod
    def get_paid_all(uid: int):
        data = (Orders.
                order_paid(uid)
                .with_('order_item')
                .with_('order_used')
                .get())
        for item in data:
            item.is_being_used = item.order_used is not None
            item.is_used = item.order_used is not None and item.order_used.status == 'confirmation'
        return data

    @staticmethod
    def get_one(Id: int):
        data = Orders.find(Id)
        return data

    @staticmethod
    def delete(Id):
        data = Orders.find(Id)
        data.delete()
        return data
